<template>
  <div class="operationPlacestyle">
    <!-- 标题 -->
    <h2>{{ datas.text }}</h2>
    <p style="color: #d40000; font-size: 14px">布局预览</p>
    <p style="color: #969799; font-size: 12px; margin: 5px 0">
      选定布局区域，在下方上传图片
    </p>
    <section class="buju buju4">
      <div
        @click="imgActive = 0"
        class="commodityType3 commodityType"
        style="width: 153px; height: 269px"
        :class="[0 === imgActive ? 'active' : '']"
      >
        <!-- <div style="font-size: 12px" v-if="!datas.imageList[0].src">
          174x272像素<br />或同等比例
        </div> -->
        <img draggable="false" src="../../../assets/img/padicon06.png" alt="" />
      </div>
      <div style="display: inline-flex; flex-direction: column; width: 157px">
        <vuedraggable v-model="datas.imageList" v-bind="dragOptions">
          <transition-group>
            <div
              @click="imgActive = index"
              class="commodityType3 commodityType"
              :class="[index === imgActive ? 'active' : '']"
              v-for="index in 2"
              :key="index">
              <div style="font-size: 12px" v-if="!datas.imageList[index].bgImage">
                174x129像素<br />或同等比例
              </div>
              <img draggable="false" v-else :src="datas.imageList[index].bgImage" alt="" />
            </div>
          </transition-group>
        </vuedraggable>
      </div>
    </section>
    <p style="color: #d40000; font-size: 12px; margin-top: 10px">请上传图片</p>
    <!-- 表单 -->
    <el-form label-width="80px" :model="datas" size="small">
      <section
        class="magiccubestyleList"
        v-for="(item, index) in datas.imageList"
        :key="index"
        v-show="imgActive === index">
        <div style="display: flex; align-items: center;">
          <!-- 图片 -->
          <div class="imag" v-show="imgActive !== 0" @click="$refs.upload.showUpload()">
            <img
              draggable="false"
              v-if="!item.bgImage"
              src="../../../assets/images/add.png"
              style="border: 1px solid #e5e5e5"
              alt=""
            />
            <div v-else style="position: relative">
              <img draggable="false" :src="item.bgImage" alt="" />
              <span>更换图片</span>
            </div>
          </div>
          <!-- 标题和链接 -->
          <div class="imgText">
            <el-input
              v-model="item.title"
              placeholder="请输入应用名称"
              size="mini"
              clearable
              style="margin-bottom: 6px"
              v-show="imgActive !== 0"
            />
            <el-input
              v-model="item.desc"
              placeholder="请输入应用描述"
              size="mini"
              clearable
              style="margin-bottom: 6px"
              v-show="imgActive !== 0"
            />
            <el-input
              v-model="item.btntext"
              placeholder="按钮文字"
              size="mini"
              clearable
              style="margin-bottom: 6px"
              v-show="imgActive !== 0"
            />
            <!-- 选择类型 -->
            <select-link
              @selectThisLink="selectThisLink"
              @clearThisLink="clearThisLink(index)"
              :linktypeurl="item.apiUrl"
              :theIndex="index">
            </select-link>
          </div>
        </div>
      </section>

      <div style="height: 20px" />

      <!-- 页面边距 -->
      <el-form-item label="页面边距" class="lef">
        <el-slider v-model="datas.pageMargin" :max="20" input-size="mini" show-input>
        </el-slider>
      </el-form-item>

      <!-- 图片间隙 -->
      <el-form-item label="图片间隙" class="lef">
        <el-slider v-model="datas.imgMargin" :max="20" input-size="mini" show-input>
        </el-slider>
      </el-form-item>

    </el-form>
    <!-- 上传图片 -->
    <uploadimg ref="upload" @uploadInformation="uploadInformation" />
  </div>
</template>
<script>
import vuedraggable from "vuedraggable"; // 拖拽组件
import uploadimg from "../../uploadImg"; // 图片上传
import SelectLink from "../../selectLink";
export default {
  name: "OperationPlacestyle",
  props: {
    datas: Object
  },
  components: {
    vuedraggable,
    uploadimg,
    SelectLink
  },
  data() {
    return {
      dragOptions: {
        // 拖拽配置
        animation: 200,
      },
      imgActive: 0, //默认选中第一个图片
    };
  },
  methods: {
    /* 替换 */
    uploadInformation(res) {
      this.datas.imageList[this.imgActive].bgImage = res;
    },
    // 选择链接
    selectThisLink(resu) {
      this.datas.imageList.forEach((it, ind) => {
        if (ind == resu.index) {
          it.apiUrl = resu.url;
          it.title = resu.name;
          it.desc = resu.note;
          it.id = resu.id;
        }
      });
    },
    // 清除链接
    clearThisLink (index) {
      this.datas.imageList[index].apiUrl = '';
    }
  }
};
</script>
<style lang="scss" scoped>
.operationPlacestyle{
  width: 100%;
  position: absolute;
  left: 0;
  overflow: hidden;
  top: 0;
  padding: 0 10px 20px;
  box-sizing: border-box;
  /* 标题 */
  h2 {
    padding: 24px 16px 24px 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #f2f4f6;
    font-size: 18px;
    font-weight: 600;
    color: #323233;
  }
  /* 布局 */
  .buju {
    &.buju4 {
      display: inline-flex;
      flex-direction: row;
      justify-content: space-around;
    }
    .commodityType{
      background-color: #fff;
      border: 1px solid #ebedf0;
      display: inline-flex;
      justify-content: center;
      align-items: center;
      color: #7d7e80;
      cursor: pointer;
      &.active {
        background: #e0edff;
        border: 1px solid #155bd4;
        color: #155bd4;
        z-index: 2;
      }
      &.commodityType3 {
        width: 153px;
        height: 130px;
        margin: 4px 0 4px 4px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  /* 列表 */
  .magiccubestyleList {
    padding: 6px 12px;
    margin: 16px 0px;
    border-radius: 2px;
    background-color: #fff;
    box-shadow: 0 0 4px 0 rgba(10, 42, 97, 0.2);
    // display: flex;
    position: relative;

    /* 删除图标 */
    .el-icon-circle-close {
      position: absolute;
      right: -10px;
      top: -10px;
      cursor: pointer;
      font-size: 19px;
    }

    /* 图片 */
    .imag {
      width: 60px;
      height: 60px;
      border-radius: 5px;
      overflow: hidden;
      position: relative;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
        display: inline-block;
      }
      span {
        background: rgba(0, 0, 0, 0.5);
        font-size: 12px;
        position: absolute;
        left: 0px;
        bottom: 0px;
        display: inline-block;
        width: 100%;
        text-align: center;
        color: #fff;
        height: 20px;
        line-height: 20px;
      }
    }

    /* 图片字 */
    .imgText {
      width: 80%;
      display: flex;
      flex-direction: column;
      box-sizing: border-box;
      padding-left: 20px;
      justify-content: space-between;
    }
  }

  /* 列表样式 */
  .commodityType {
    display: flex;
    justify-content: space-around;
    align-items: center;
    img {
      display: inline-block;
      width: 30px;
      height: 25px;
      // text-align: center;
      // line-height: 32px;
      // background: #fff;
      border: 1px solid #ebedf0;
      // color: #979797;
      margin: 0 1px;
      cursor: pointer;
      transition: all 0.5s;

      &:hover {
        border: 1px solid #155bd4;
        color: #155bd4;
      }

      &.active {
        border: 1px solid #155bd4;
        background-color: #e0edff;
        color: #155bd4;
      }
    }
  }
}
</style>
